package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.StEquipmentAccessory;
import com.ruoyi.system.api.domain.StInstallationQualityReport;
import com.ruoyi.system.api.domain.StMajorPart;
import com.ruoyi.system.api.service.IStEquipmentAccessoryService;
import com.ruoyi.system.api.service.IStInstallationQualityReportService;
import com.ruoyi.system.api.service.IStMajorPartService;
import com.ruoyi.system.api.service.IStReportPortService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 安装质量报告
 * @ClassName InstallationQualityReportController.java
 * @date 2020/3/9 2:41 下午
 * @author yzg
 */
@Api(tags="安装质量报告")
@RestController
@RequestMapping("/api/cc/installation/quality/report/")
public class InstallationQualityReportController extends BaseController {

    @Autowired
    private IStReportPortService reportPortService;

    @Autowired
    private IStInstallationQualityReportService installationQualityReportService;

    @Autowired
    private IStMajorPartService majorPartService;

    @Autowired
    private IStEquipmentAccessoryService equipmentAccessoryService;

    private static final Logger log = LoggerFactory.getLogger(InstallationQualityReportController.class);

    /**
     *  添加安装质量报告
     *
     * @param installationQualityReport
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 4:06 下午
     */
    @Log(title = "添加安装质量报告", businessType = BusinessType.INSERT)
    @PostMapping("addInstallationQualityReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加安装质量报告", httpMethod = "POST", notes = "添加安装质量报告")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addInstallationQualityReport(@RequestBody StInstallationQualityReport installationQualityReport) {
        try {
            return installationQualityReportService.addInstallationQualityReport2(installationQualityReport);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  修改安装质量报告
     *
     * @param installationQualityReport
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 4:06 下午
     */
    @Log(title = "修改安装质量报告", businessType = BusinessType.UPDATE)
    @PostMapping("updateInstallationQualityReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "修改安装质量报告", httpMethod = "POST", notes = "修改安装质量报告")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updateInstallationQualityReport(@RequestBody StInstallationQualityReport installationQualityReport) {
        try {
            return installationQualityReportService.updateInstallationQualityReport(installationQualityReport);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  提交安装质量报告
     *
     * @param id	安装质量报告主键ID
     * @param enginnerId	提交的工程师ID
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 4:07 下午
     */
    @RepeatSubmit
    @Log(title = "提交安装质量报告", businessType = BusinessType.UPDATE)
    @GetMapping("installationQualityReportSubmit")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "提交安装质量报告", httpMethod = "GET", notes = "提交安装质量报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "安装质量报告主键ID", name = "id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "提交的工程师ID", name = "enginnerId", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> installationQualityReportSubmit(@RequestParam Long id, @RequestParam Long enginnerId){
        try {
            return installationQualityReportService.installationQualityReportSubmit(id, enginnerId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看安装质量报告
     *
     * @param id
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 4:08 下午
     */
    @GetMapping("detailInstallationQualityReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看安装质量报告", httpMethod = "GET", notes = "查看安装质量报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "安装质量报告主键ID", name = "id", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> detailInstallationQualityReport(@RequestParam Long id) {
        try {
            return installationQualityReportService.detailInstallationQualityReport(id);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  添加主要备件信息
     *
     * @param majorPart
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 3:10 下午
     */
    @Log(title = "添加主要备件信息", businessType = BusinessType.INSERT)
    @PostMapping("addMajorPart")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加主要备件信息", httpMethod = "POST", notes = "添加主要备件信息")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addMajorPart(@RequestBody StMajorPart majorPart){
        try {
            return majorPartService.addMajorPart(majorPart);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看主要备件列表
     *
     * @param serviceNo
     * @param instrumentNo
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 3:13 下午
     */
    @GetMapping("selectMajorParts")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看主要备件列表", httpMethod = "GET", notes = "查看主要备件列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "仪器主键ID", name = "instrumentNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectMajorParts(
            @RequestParam(value="instrumentNo",required=true) String instrumentNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="serviceNo",required=true) String serviceNo
    ){
        try {
            return majorPartService.selectMajorParts(instrumentNo, enginnerId, serviceNo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  移除主要备件信息
     *
     * @param partsId
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 3:17 下午
     */
    @Log(title = "移除主要备件信息", businessType = BusinessType.DELETE)
    @GetMapping("removeMajorPart")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "移除主要备件信息", httpMethod = "GET", notes = "移除主要备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "仪器主键ID", name = "instrumentNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "提交的工程师ID", name = "enginnerId", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "主要备件主键ID", name = "partsId", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> removeMajorPart(
            @RequestParam(value="instrumentNo",required=true) String instrumentNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="partsId",required=true) String partsId,
            @RequestParam(value="serviceNo",required=true) String serviceNo
    ){
        try {
            return majorPartService.removeMajorPart(instrumentNo, enginnerId, partsId, serviceNo);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  添加附属设备信息
     *
     * @param equipmentAccessory
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 3:19 下午
     */
    @Log(title = "添加附属设备信息", businessType = BusinessType.INSERT)
    @PostMapping("addEquipmentAccessory")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加附属设备信息", httpMethod = "POST", notes = "添加附属设备信息")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addEquipmentAccessory(@RequestBody StEquipmentAccessory equipmentAccessory){
        try {
            return equipmentAccessoryService.addEquipmentAccessory(equipmentAccessory);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看附属设备列表
     *
     * @param instrumentNo
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 3:21 下午
     */
    @GetMapping("selectEquipmentAccessorys")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看附属设备列表", httpMethod = "GET", notes = "查看附属设备列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "仪器主键ID", name = "instrumentNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectEquipmentAccessorys(
            @RequestParam(value="instrumentNo",required=true) String instrumentNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="serviceNo",required=true) String serviceNo
    ){
        try {
            return equipmentAccessoryService.selectEquipmentAccessorys(instrumentNo, enginnerId, serviceNo);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  移除附属设备信息
     *
     * @param assetNo 附属设备表主键
     * @param enginnerId 提交的工程师ID
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 3:22 下午
     */
    @Log(title = "移除附属设备信息", businessType = BusinessType.DELETE)
    @GetMapping("removeEquipmentAccessory")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "移除附属设备信息", httpMethod = "GET", notes = "移除附属设备信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "仪器主键ID", name = "instrumentNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "提交的工程师ID", name = "enginnerId", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "附属设备主键ID", name = "assetNo", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> removeEquipmentAccessory(
            @RequestParam(value="instrumentNo",required=true) String instrumentNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="assetNo",required=true) String assetNo,
            @RequestParam(value="serviceNo",required=true) String serviceNo
    ){
        try {
            return equipmentAccessoryService.removeEquipmentAccessory(instrumentNo, enginnerId, assetNo, serviceNo);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看备件信息
     *  已完成报告【服务报告或电话解决报告】中的备件信息。
     *
     * @param serviceNo
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 2:53 下午
     */
    @GetMapping("selectReportPort")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看备件信息", httpMethod = "GET", notes = "查看备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectReportPort(@RequestParam (value="serviceNo",required=true) String serviceNo,
                                                @RequestParam(value="helpId",required=true) String helpId,
                                                @RequestParam(value="type",required=false) String type) {
        try {
            return reportPortService.selctcInstallationQualityReportPort(serviceNo,helpId,type);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看安装质量报告备件信息
     *
     *
     * @param serviceNo
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 2:53 下午
     */
    @GetMapping("selectReportPortByInstallation")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看备件信息", httpMethod = "GET", notes = "查看备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "helpId", name = "helpId", required = false, dataType = "helpId", paramType = "query"),
            @ApiImplicitParam(value = "enginnerId", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "type", name = "type", required = false, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectReportPortByInstallation(@RequestParam (value="serviceNo",required=true) String serviceNo,
                                                @RequestParam(value="helpId",required=true) String helpId,
                                                @RequestParam(value="reportId",required=true) String reportId,
                                                @RequestParam(value="type",required=false) String type) {
        try {
            return reportPortService.selctcInstallationQualityReportPortByInstallation(serviceNo,helpId,type,reportId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看安装质量报告备件信息
     *
     *
     * @param serviceNo
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/9 2:53 下午
     */
    @GetMapping("selectReportPortByDel")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看备件信息", httpMethod = "GET", notes = "查看备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selctcInstallationQualityReportPortByDel(@RequestParam (value="serviceNo",required=true) String serviceNo,
                                                              @RequestParam(value="helpId",required=true) String helpId,
                                                              @RequestParam(value="type",required=false) String type) {
        try {
            return reportPortService.selctcInstallationQualityReportPortByDel(serviceNo,helpId,type);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }



    /**
     * 安装质量报告页面自动带入项数据查询
     * @methodName: initData
     * @description: TODO
     * @param serviceNo
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-03-30 10:08
    **/
    @GetMapping("initData")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "安装质量报告页面自动带入项数据查询", httpMethod = "GET", notes = "安装质量报告页面自动带入项数据查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> initData(
            @RequestParam(value="serviceNo",required=true) String serviceNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId
    ) {
        try {
            return installationQualityReportService.initData(serviceNo, enginnerId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 安装质量报告软件及其它设备自动带入项数据查询
     * @methodName: initSoftwareAndPartsData
     * @description: TODO
     * @param serviceNo
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-03-31 9:29
    **/
    @GetMapping("initSoftwareAndPartsData")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "安装质量报告软件及其它设备自动带入项数据查询", httpMethod = "GET", notes = "安装质量报告软件及其它设备自动带入项数据查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "设备序列号", name = "instrumentCode", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> initSoftwareAndPartsData(
            @RequestParam(value="serviceNo",required=true) String serviceNo,
            @RequestParam(value="instrumentCode",required=true) String instrumentCode
    ) {
        try {
            return installationQualityReportService.initSoftwareAndPartsData(serviceNo,instrumentCode);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 根据主键ID查询安装质量报告
     * @methodName: getInstallationQualityReport
     * @description: TODO
     * @param id
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-03-31 10:29
    **/
    @GetMapping("getInstallationQualityReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "根据主键ID查询安装质量报告", httpMethod = "GET", notes = "根据主键ID查询安装质量报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "安装质量报告主键ID", name = "id", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getInstallationQualityReport(
            @RequestParam(value="id",required=true) String id
    ) {
        try {
            StInstallationQualityReport stInstallationQualityReport = installationQualityReportService.selectStInstallationQualityReportById(Long.parseLong(id));
            return new ResponseWithData<>().success(stInstallationQualityReport).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }






}
